#include "seqstack.h"

int match_kuohao();
int main()
{
    int continueSign = 0;
    char c[100];
    do{
        do{
            fflush(stdin);
            printf("Please enter expressions:\n");
            gets(c);
        }while(!c[0]);

        if(match_kuohao(c)) printf("TRUE\n"); else printf("FALSE\n");

        printf("0 to quit. 1 to continue.\n");
        scanf("%d", &continueSign);
    }while(continueSign);
}

int match_kuohao(char c[]){
    int i;
    seqstack s;
    init(&s);
    for(i=0; c[i]; i++){
        switch(c[i]){
        case '{':
        case '[':
        case '(': push(&s, c[i]); break;
        case ')':   if(!empty(s)&&pop(&s)=='(') break;
                    else return 0;
        case ']':   if(!empty(s)&&pop(&s)=='[') break;
                    else return 0;
        case '}':   if(!empty(s)&&pop(&s)=='{') break;
                    else return 0;
        }
    }
    return (empty(s));
}
